home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / tpschk11.arc / CRC_GEN.INC next >
Text File  |  1991-04-28  |  2KB  |  58 lines

  1.  
  2.  
  3. Procedure Crc_gen( Var s; length : Integer);
  4.  
  5. (*
  6.    This CCITT (16 bit) CRC generation routine was adapted from the
  7.  Public Domain program FILETEST and this particular routine was
  8.  written by David Dantowitz of DEC.  The routine has been modified
  9.  for use with The SelfChk Unit to the point where it may be barely
  10.  recognizable.
  11.                                     - Mike Durkin
  12.  *)
  13.    
  14.  
  15. Begin
  16.  
  17. inline(
  18.  
  19. $c4/$7e/<s/                {les di,s[bp]              (es:di points to array)}
  20. $A1/crc_ccitt/             {mov ax,crc_ccitt          (initial CRC value)    }
  21. $8b/$8e/length/            {mov cx,length             (# bytes to compute)   }
  22. $be/table_ccitt/           {mov si,offset table_ccitt (table address)        }
  23.  
  24.  
  25. { next:  }
  26.  
  27. $26/$32/$05/               {xor al,es:[di]          CRC = CRC XOR next byte  }
  28. $47/                       {inc di                  (point to next byte)     }
  29.  
  30. { intermediate steps, see comments for overall effect }
  31.  
  32. $31/$db/                   {xor bx,bx               (bx <- 0)                }
  33. $86/$d8/                   {xchg al,bl              (bx <- ax and 0FF)       }
  34. $86/$e0/                   {xchg al,ah              (ax <- ax shr 8)         }
  35. $d1/$e3/                   {shl bx,1                (bx <- bx+bx)            }
  36.  
  37. $33/$00/                   {xor ax,[bx+si]          CRC = (CRC shr 8) XOR
  38.                                                           table[CRC and 0FF] }
  39.  
  40. $e2/$f0/                   {loop next               (count <- count -1)      }
  41.  
  42. $A3/crc_ccitt);            {mov crc_ccitt,ax        (crc_ccitt := CRC)       }
  43.  
  44.  
  45. (*  basic algorithm expressed above
  46.  
  47. crc_ccitt := initial_crc
  48.  
  49. For each byte Do
  50. Begin
  51.   crc := crc XOR next_byte;
  52.   crc := (crc shr 8) XOR table_ccitt [crc and $FF];
  53. End;
  54.  
  55. crc_ccitt := crc;
  56. *)
  57. End;
  58.